package com.ttflutter.tkvideodownloader.api

import androidx.paging.DataSource
import androidx.room.*

/**
 * @author Afra55
 * @date 2020/5/21
 * A smile is the best business card.
 */
@Dao
interface RedditDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(media: MediaEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertAll(media: SavedMediaEntity)

    @Query("SELECT * FROM media WHERE a=:mediaId")
    fun getMediaById(mediaId: String): MediaEntity?

    @Query("SELECT * FROM saved_media WHERE a=:mediaId")
    fun getSavedMediaById(mediaId: String): SavedMediaEntity?

    @Query("SELECT * FROM media ORDER BY saved_time DESC")
    fun pageAllMedia(): DataSource.Factory<Int, MediaEntity>

    @Query("SELECT * FROM saved_media ORDER BY saved_time DESC")
    fun pageAllSavedMedia(): DataSource.Factory<Int, SavedMediaEntity>
    @Query("SELECT * FROM saved_media WHERE what=0 ORDER BY saved_time DESC")
    fun pageAllVideoSavedMedia(): DataSource.Factory<Int, SavedMediaEntity>

    @Query("SELECT * FROM saved_media WHERE what=1 ORDER BY saved_time DESC")
    fun pageAllMusicSavedMedia(): DataSource.Factory<Int, SavedMediaEntity>
    @Delete
    fun delete(mediaEntity: MediaEntity)
    @Delete
    fun delete(mediaEntity: SavedMediaEntity)
}